//
//  ITNewsHeaderView.m
//  InTime
//
//  Created by zhangjia on 15/9/9.
//  Copyright (c) 2015年 ClownYoJoy. All rights reserved.
//

#import "ITNewsHeaderView.h"
#import "GeneralHeader.h"
#import "UIImageView+WebCache.h"
#import "NewsListModel.h"

@interface ITNewsHeaderView ()

@property (strong , nonatomic) UIScrollView *scrollView;
@property (strong, nonatomic) NSMutableArray *titleArray;
@property (strong, nonatomic) NSMutableArray *imgArray;
@property (strong, nonatomic) UILabel *titleLabel;


@end

@implementation ITNewsHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithReuseIdentifier:reuseIdentifier];
    if (self) {
        self.userInteractionEnabled = YES;
        self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kWidth, 200)];
        self.scrollView.backgroundColor = [UIColor skyBlueColor];
        self.scrollView.contentSize = CGSizeMake(kWidth * 5, 200);
        self.scrollView.pagingEnabled = YES;//整页滑动
        self.scrollView.showsHorizontalScrollIndicator = NO;//取消水平滑动条显示
        [self.contentView addSubview:self.scrollView];
        
        self.imgArray = [NSMutableArray array];
        self.titleArray = [NSMutableArray array];
        
        for (int i = 0; i < 5; i ++) {
            //图片
            UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(kWidth * i, 0, kWidth, 170)];
            img.image = [UIImage imageNamed:@"for-check"];
            [self.scrollView addSubview:img];
            [self.imgArray addObject:img];
            //标题
            UILabel *title = [[UILabel alloc] initWithFrame:CGRectMake(20 + kWidth * i, 170, kWidth, 30)];
            title.textColor = [UIColor whiteColor];
            [self.scrollView addSubview:title];
            [self.titleArray addObject:title];
        }
        
        UIPageControl *page = [[UIPageControl alloc] initWithFrame:CGRectMake(0, 170, 10, 30)];
        page.backgroundColor = [UIColor pinkColor];
        page.numberOfPages = 5;
        page.currentPage = 1;
        page.pageIndicatorTintColor = [UIColor grayColor];
        page.currentPageIndicatorTintColor = [UIColor whiteColor];
        [self.contentView addSubview:page];
    }

    return self;
}

- (void)setModel:(NewsListModel *)model {
    _model = model;
    NSLog(@"ads:%@",model.ads);
    
    for (int i = 0; i < 5; i ++)
    {
        [self.imgArray[i] sd_setImageWithURL:[model.ads[i] objectForKey:@"imgsrc"]];
        [self.titleArray[i] setText:[model.ads[i] objectForKey:@"title"]];
    }
    
}

@end
